<%--
  Created by IntelliJ IDEA.
  User: v.tsapaev
  Date: 26.05.12
  Time: 15:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title></title>
    <script type="text/javascript" language="javascript" src="../resources/js/util/jquery-1.7.2.js"
            charset="UTF-8"></script>
    <script type="text/javascript" language="javascript" src="../resources/js/util/json2.js"
            charset="UTF-8"></script>
    <script type="text/javascript" language="javascript" src="../resources/js/index.js" charset="UTF-8"></script>
    <link type="text/css" rel="stylesheet" href="../resources/css/index.css">
</head>
<body>
<div id="container">
    <c:import url="header.jsp"/>

    <c:choose>
        <c:when test="${not empty sessionScope.order.bookMap}">
            <form id="confirm-order-form" action="buy.htm" method="post">
                <table class="table-center">
                    <tr>
                        <th><div>Название книги</div></th>
                        <th><div>Цена</div></th>
                        <th><div>Количество</div></th>
                    </tr>

                    <c:set var="totalSum" value="${0}" />
                    <c:set var="totalCount" value="${0}" />
                    <c:forEach var="book" items="${sessionScope.order.bookMap}">
                        <c:set var="totalSum" value="${totalSum + book.key.price * book.value}" />
                        <c:set var="totalCount" value="${totalCount + book.value}" />
                        <tr id="book-row-${book.key.bookId}">
                            <td><div id="book-name-${book.key.bookId}">${book.key.name}</div></td>
                            <td><div id="book-price-${book.key.bookId}">${book.key.price}</div></td>
                            <td>
                                <div>
                                    <input
                                        id="book-count-input-${book.key.bookId}"
                                        value="${book.value}"
                                        class="digit"
                                        type="text">
                                </div>
                            </td>
                            <td>
                                <div>
                                    <input id="book-delete-button-${book.key.bookId}"
                                           type="button"
                                           value="удалить"
                                           onclick="deleteBook(this)">
                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                    <tr>
                        <td><div id="total" class="total">Итого:</div></td>
                        <td><div id="totalSum" class="total number">${totalSum}</div></td>
                        <td><div id="totalCount" class="total number">${totalCount}</div></td>
                        <td><div></div></td>
                    </tr>
                </table>
                <div><input id="confirm-order-button" type="submit" value="Подтвердить заказ" disabled="disabled"></div>
            </form>
        </c:when>

        <c:otherwise>
            Корзина пуста
        </c:otherwise>
    </c:choose>
</div>
</body>
</html>